home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11949 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: [Q] how to specify binary values
  5. Date: Wed, 27 Mar 96 20:53:36 GMT
  6. Organization: none
  7. Message-ID: <827960016snz@genesis.demon.co.uk>
  8. References: <4ihqi0$9mt@brain.npiec.on.ca> <4isvnd$jkf@newshost.cyberramp.net> <4j4li6INNmbf@duncan.cs.utk.edu> <4j646k$ad0@news.xs4all.nl>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4j646k$ad0@news.xs4all.nl> falstaff@xs4all.nl "Falstaff" writes:
  15.  
  16. ...
  17.  
  18. >>#define BINARY_NUM32(xx_d31,xx_d30,  xx_d29,xx_d28,xx_d27,xx_d26,xx_d25,xx_d24,>xx_d23,xx_d22,xx_d21,xx_d20, xx_d19,xx_d18,xx_d17,xx_d16,xx_d15,xx_d14,xx_d13,
  19. >xx_d12,xx_d11,xx_d10, xx_d9,xx_d8,xx_d7,xx_d6,xx_d5,xx_d4,xx_d3,xx_d2,xx_d1,
  20. >xx_d0)           \
  21. >>                ((BINARY_NUM16(xx_d31,xx_d30, xx_d29,xx_d28,xx_d27,xx_d26,
  22.                    ^
  23.                  (long)
  24.  
  25.  
  26. >xx_d25,  \
  27. >>         xx_d24,xx_d23,xx_d22,xx_d21,xx_d20,xx_d19,xx_d18,xx_d17,xx_d16) <<
  28. > 16) |  \
  29. >                                                                             ^^
  30. >                                       Actually I think you better use 16L here
  31.  
  32. >> and << perform the integral promotions independently on each operand unlike,
  33. for example, + which performs the usual arithmetic conversions (i.e. combining
  34. types from both operands). So this doesn't force the left hand operand (or
  35. indeed the result of << ) to be promoted to long. You need an explicit cast
  36. where I have indicated instead.
  37.  
  38. >>         BINARY_NUM16( xx_d15,xx_d14,xx_d13,xx_d12,xx_d11,xx_d10, \
  39. >>         xx_d9,xx_d8,xx_d7,xx_d6,xx_d5,xx_d4,xx_d3,xx_d2,xx_d1,xx_d0))
  40. >>
  41. >>  x = BINARY_NUM32(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,>1,1);
  42.  
  43. >Please hold while I find a bag to vomit into...
  44. >
  45. >Thank you, I feel much better now.
  46. >
  47. >Pity K&R didn't think about 0b01020101.
  48.  
  49. 2?
  50.  
  51. Then of course there is the true horror of 64 bit systems (and beyond).
  52.  
  53. -- 
  54. -----------------------------------------
  55. Lawrence Kirby | fred@genesis.demon.co.uk
  56. Wilts, England | 70734.126@compuserve.com
  57. -----------------------------------------
  58.